package com.itheima.demo02;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

//Stream流中间操作方法
public class StreamClass05 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>(List.of("aaa","bb","c","bb","ac"));
        Stream<String> stream1 = list.stream();
        //method1(list);
        //method2(list);
        //method3(list);
        //method4(list);
        //method5(stream1);
        //去重
        //method6(stream1);
        //method7(list);
        //将字符串集合转换为整数集合
        //method8();
    }

    private static void method8() {
        ArrayList<String> list1 = new ArrayList<>(List.of("111","22","3"));
        list1.stream().sorted((s1,s2) -> s1.length() - s2.length())
                .map(s -> Integer.parseInt(s))
                .forEach(s -> System.out.println(s));
    }

    private static void method7(ArrayList<String> list) {
        list.stream().sorted((s1,s2) ->{
            int result = s1.length() - s2.length();
            result = result == 0 ? s1.compareTo(s2) : result;
            return result;
        }).distinct().forEach(s -> System.out.println(s));
    }

    private static void method6(Stream<String> stream1) {
        stream1.distinct().forEach(s -> System.out.println(s));
    }

    private static void method5(Stream<String> stream1) {
        ArrayList<String> list1 = new ArrayList<>(List.of("dd","eee"));
        Stream<String> stream2 = list1.stream();
        Stream<String> stream = Stream.concat(stream1, stream2);
        stream.forEach(s -> System.out.println(s));
    }

    private static void method4(ArrayList<String> list) {
        list.stream().limit(2).forEach(s -> System.out.println(s));
    }

    private static void method3(ArrayList<String> list) {
        list.stream().skip(2).forEach(s -> System.out.println(s));
    }

    private static void method2(ArrayList<String> list) {
        list.stream().filter(s -> s.startsWith("a")).forEach(s -> System.out.println(s));
    }

    private static void method1(ArrayList<String> list) {
        list.stream().filter(s -> s.length() ==3).forEach(s -> System.out.println(s));
    }
}
